package com.learnyou.server.xingzuo.dao.repository.service.impl;

import cn.hutool.core.util.StrUtil;
import com.learnyou.server.xingzuo.dao.repository.entity.Account;
import com.learnyou.server.xingzuo.dao.repository.mapper.AccountMapper;
import com.learnyou.server.xingzuo.dao.repository.service.IAccountService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;

/**
 * <p>
 * 账号 服务实现类
 * </p>
 *
 * @author heweifeng
 * @since 2023-11-30
 */
@Service
public class AccountServiceImpl extends ServiceImpl<AccountMapper, Account> implements IAccountService {

    @Override
    public List<Account> findByDeviceNo(String deviceNo) {
        if (StrUtil.isEmpty(deviceNo)) {
            return Collections.emptyList();
        }
        return lambdaQuery().eq(Account::getCode, deviceNo).list();
    }

    @Override
    public Account findByDeviceNoAndPhone(String deviceNo, String phone) {
        if (!StrUtil.isAllNotEmpty(deviceNo, phone)) {
            return null;
        }
        return lambdaQuery().eq(Account::getCode, deviceNo).eq(Account::getPhone, phone).last("limit 1").one();
    }

    @Override
    public List<Account> findByPhone(String phone) {
        if (StrUtil.isEmpty(phone)) {
            return Collections.emptyList();
        }
        return lambdaQuery().eq(Account::getPhone, phone).list();
    }
}
